//
//  GHShopCardTableViewCell.m
//  GodHorses
//
//  Created by Mac on 2017/11/20.
//  Copyright © 2017年 stoneobs@icloud.com. All rights reserved.
//

#import "GHShopCardTableViewCell.h"
@interface GHShopCardTableViewCell()
@property(nonatomic, strong) UIImageView                     *iconImageView;
@property(nonatomic, strong) STLabel                        *titleLable;
@property(nonatomic, strong) STLabel                        *moneyLable;
@property(nonatomic, strong) STLabel                        *timeLable;
@end
@implementation GHShopCardTableViewCell
+ (CGFloat)cellHeight{
    return 100;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self configSubView];
    }
    return self;
}
#pragma mark --subView
- (void)configSubView{
    self.backgroundColor = [UIColor whiteColor];
    self.chosedButton = [[STButton alloc] initWithFrame:CGRectMake(10, 0, 44, 44)
                                                     title:nil
                                                titleColor:nil
                                                 titleFont:0
                                              cornerRadius:0
                                           backgroundColor:nil
                                           backgroundImage:nil
                                                     image:[UIImage imageNamed:@"PC_gouxuan_background"]];
    [self.chosedButton setImage:[UIImage imageNamed:@"PC_gouxuan__selected_red"]
                       forState:UIControlStateSelected];
    self.chosedButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    self.chosedButton.centerY = [GHShopCardTableViewCell cellHeight]/2;
    [self addSubview:self.chosedButton];
    
    self.iconImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.chosedButton.st_right, 10, 80, 80)];
    [self addSubview:self.iconImageView];
    

    self.titleLable =  [[STLabel alloc] initWithFrame:CGRectMake(self.iconImageView.right + 10, 15, UIScreenWidth - 20 - self.iconImageView.st_right, 16)
                                                text:@"--------"
                                           textColor:GH_secendTextColor
                                                font:14
                                         isSizetoFit:NO
                                       textAlignment:NSTextAlignmentLeft];
    [self addSubview:self.titleLable];
    
    self.moneyLable =  [[STLabel alloc] initWithFrame:CGRectMake(self.iconImageView.right + 10, self.titleLable.st_bottom + 5, UIScreenWidth - 20 - self.iconImageView.st_right, 18)
                                                   text:@"--------"
                                              textColor:GH_redColor
                                                   font:15
                                            isSizetoFit:NO
                                          textAlignment:NSTextAlignmentLeft];
    [self addSubview:self.moneyLable];
    
    self.timeLable =  [[STLabel alloc] initWithFrame:CGRectMake(self.iconImageView.right + 10, self.moneyLable.st_bottom + 4, UIScreenWidth - 20 - self.iconImageView.st_right, 18)
                                                 text:@"--------"
                                            textColor:GH_secendTextColor
                                                 font:13
                                          isSizetoFit:NO
                                        textAlignment:NSTextAlignmentLeft];
    [self addSubview:self.timeLable];
}
- (void)setModel:(GHShopCardModel *)model{
    _model = model;
    self.chosedButton.selected = [model.selected boolValue];
    
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.g_img] placeholderImage:GH_placeHoderImage];
    
    self.titleLable.text = [NSString stringWithFormat:@"%@共%@件",model.g_name,model.g_num];
    CGFloat maxPrice = [model.g_num integerValue] * [model.m_price floatValue];
    self.moneyLable.text = [NSString stringWithFormat:@"￥%@  %0.2f",model.total_price,maxPrice];
    self.moneyLable.attributedText =
    [self.moneyLable.text st_convertAttributeStringWithKeyWord:[NSString stringWithFormat:@"%0.2f",maxPrice]
                                                    attributes:@{NSForegroundColorAttributeName:GH_secendTextColor,
                                                                 NSStrikethroughStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle],
                                                                NSFontAttributeName:[UIFont systemFontOfSize:13]
                                                                 }];
    
    NSDate * date = [NSDate dateWithTimeIntervalSince1970:[model.add_time integerValue]].st_localDate;
    self.timeLable.text = date.st_yyyyMMddhhmmssWithDate;
}
@end
